package com.ziyun.pop.mall.module.user.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import com.service.common.protocol.ResultCode;
import com.service.goods.api.SubSellerService;
import com.service.goods.constant.GoodsResult;
import com.service.goods.model.seller.SellerInfoVO;
import com.service.soa.service.impl.BaseServiceImpl;
import com.service.ucenter.exception.UserException;
import com.service.utils.push.umeng.JsonResult;
import com.ziyun.pop.mall.system.config.HttpRequestLocal;





/**
 * 商家信息service
 * @author husong
 *
 */
@Service
@Transactional
public class PopSellerInfoService extends BaseServiceImpl {
	
	@Autowired
	private SubSellerService subSellerService;
	@Autowired
    private HttpRequestLocal httpRequestLocal;
	
	public JsonResult<SellerInfoVO> getSellerInfoVO() throws UserException {
				
		long sellerId = getSellerId();
		GoodsResult<SellerInfoVO> sellerDetails = subSellerService.getSellerDetails(sellerId, "true");
		SellerInfoVO sellerInfoVO = sellerDetails.getData();
		return JsonResult.success(sellerInfoVO);
	}
	
	/**
	 * 获取sellerId
	 */
	public long getSellerId() {
		Object seller = httpRequestLocal.getSessionValue("sellerId");
		if(StringUtils.isEmpty(seller)){
			throw new UserException(ResultCode.MERCHANTS_NON_EXISTENT);//商户不存在
		}
		long sellerId = Long.valueOf(String.valueOf(seller)).longValue();
		return sellerId;
	}
}
